﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Runnergame.View
{
    class Camera
    {
        Vector2 m_resolution;

        float scaleX;
        float scaleY;
        float displaceX;
        float displaceY;
        Vector2 cameraPosition;
        Vector2 movement;
        Viewport vp;

        public Camera(Viewport viewPort)
        {
            vp = viewPort;
            cameraPosition = Vector2.Zero;
            movement = Vector2.Zero;

            m_resolution.X = viewPort.Width;
            m_resolution.Y = viewPort.Height;

            scaleX = viewPort.Width / 10;
            scaleY = viewPort.Height / 10;
        }

        internal Rectangle getVisualRect(float logicalX, float logicalY, float modelRadius)
        {

            float ViewRadiusX = modelRadius * scaleX;
            float ViewRadiusY = modelRadius * scaleY;

            int screenX = (int)((logicalX * scaleX - displaceX * 60) - ViewRadiusX);
            int screenY = (int)((logicalY * scaleY + displaceY) - ViewRadiusY);

            return new Rectangle(screenX, screenY, (int)(ViewRadiusX * 2.0f), (int)(ViewRadiusY * 2.0f));

        }
        internal Rectangle getVisualTileRect(float logicalX, float logicalY, float modelRadius)
        {

            float ViewRadiusX = modelRadius * scaleX;
            float ViewRadiusY = modelRadius * scaleY;

            int screenX = (int)((logicalX * scaleX) - ViewRadiusX);
            int screenY = (int)((logicalY * scaleY) - ViewRadiusY);

            return new Rectangle(screenX, screenY, (int)(ViewRadiusX * 2.0f), (int)(ViewRadiusY * 2.0f));

        }

        public Rectangle getVisualTileRect(Rectangle logicalRect)
        {

            float ViewRadiusX = logicalRect.Width * scaleX;
            float ViewRadiusY = logicalRect.Height * scaleY;

            int screenX = (int)((logicalRect.X * scaleX) - ViewRadiusX);
            int screenY = (int)((logicalRect.Y * scaleY) - ViewRadiusY);

            return new Rectangle(screenX, screenY, (int)(ViewRadiusX), (int)(ViewRadiusY));

        }

        internal void Update(GameTime gameTime, Model.Player player) 
        {
            player.playerPosition = movement;
            
        
        }
        internal void CameraMovement(float displace)
        {
            displaceX = displace;
        
        }
    }
}
